<?php
namespace Site\Controller;
class TaskController extends CommonController {
    public function index() {
        $data = $this->getPageList(M('Task'),array('sid'=>$this->sid),'sid desc');
        $this->display();
    }

    public function add() {
        if(IS_POST) {
            D('Task','Mysql')->addTask(I('post.'));
            $this->success('抓取任务添加成功','/Task');
        }else {

            $categoryList = D('Category','Mysql')->getList(array(
                'status'    =>  1,
                'sid'       =>  $this->sid,
            ),'id,title');

            $parseList = D('Parse','Mysql')->getList(array(
                'status'    =>  1
            ),'id,title');

            $this->assign(array(
                'categoryList'  =>  $categoryList,
                'parseList'     =>  $parseList
            ));
            $this->display();
        }
    }

    public function update() {
        if(IS_POST) {
            D('Task','Mysql')->updateTask(I('post.'));
            $this->success('抓取任务修改成功','/Task');
        }else {
            $id = I('get.id');
            verify($id,'isID','非法抓取任务ID');

            $taskInfo = M('Task')->find($id);
            verify($taskInfo,'notEmpty','抓取任务不存在');

            $parseList = M('Parse')->where("status=1")->select();

            $this->assign(array(
                'taskInfo'  =>  $taskInfo,
                'parseList' =>  $parseList
            ));
            $this->setTitle('抓取任务','编辑任务:' . $taskInfo['title']);
            $this->display();
        }
    }
}
?>
